$(function(){

	$('#dialog-progress').dialog({
		bgiframe: true,
		autoOpen: false,
		modal: true,
		height: 100,
		draggable: false,
		closeOnEscape: false,
		title: 'Completamento Azione...'

	});

	$("#dialog-new-event").dialog({
		bgiframe: true,
		autoOpen: false,
		modal: true,
		buttons: {
			Ok: function(){
				$(this).dialog('close');
			}
		}
	});

	$('#closeAlert').click(function(){
		$('#alertinfo').hide('blind',null,500)
	});

	$('#action-wrapper a').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);

	function createVisualTBLStyle(tablename){
	
			
			$('#' + tablename + ' tbody tr').hover(function(){
				$(this).addClass('simplyTableHover');
			}, function(){
				$(this).removeClass('simplyTableHover');
			});
			
			$('#' + tablename + ' tbody').selectable();
			
	}

});



$.fn.extend({ setCheckedValue: function(options, value){}

});


jQuery.fn.check = function(options, value) {

	var settings = jQuery.extend({type: "bool"}, options);
	var value = value || "0";
	switch(settings.type) {
		case 'bool':
			if(value == "1"){this.attr('checked',true);}
			else{this.attr('checked',false);} 
		break;
		case 'string':
			if(this.val() == value){this.attr('checked',true);}
			else{this.attr('checked',false);}
		break;
	}
};

$.fn.extend({ toggleclose: function() {
	    return this.each(function() {
				var name = $(this).attr('name');
				
				if ($('#' + name + '-content').css("display") == 'none') {
					$('#' + name + '-content').show('blind', null, 500);
					$('#' + name + '-img').attr('src','images/up.gif');
				}
				else {
					$('#' + name + '-content').hide('blind', null, 500);
					$('#' + name + '-img').attr('src','images/down.gif');
				}

				
	    });
	} 
});

$.fn.extend({ hovertablestyle: function() {
	    return this.each(function() {
				$(this).find('tbody tr').hover(function(){
					$(this).addClass('simplyTableHover');
				}, function(){
					$(this).removeClass('simplyTableHover');
				});
				$(this).find('tbody').selectable();
	    });
	} 
});



$.fn.extend({ StartAjaxLoader: function(){
		return this.each(function(){
			$('#alertmessage').html('<img src="images/ajax-loader.gif" />Completamento azione')
			$(this).removeClass('ui-helper-hidden');
			$(this).addClass('ui-widget-overlay');
		})
	}
});

$.fn.extend({ StopAjaxLoader: function(){
		return this.each(function(){
			$(this).removeClass('ui-widget-overlay');
			$(this).addClass('ui-helper-hidden');
		})
	}
});
$.fn.extend({ reset: function(){
		return this.each(function(){
			$(this).is('form') && this.reset();
		})
	}
});